<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/8/23
 * Time: 13:08
 */

namespace Wechat\Controller;


use Common\Controller\AdminbaseController;
/*后台会员控制器*/
class UserController extends AdminbaseController
{
    /*用户管理主页*/
    public function index()
    {
        $count      = M('wechatuser')->order('id desc')->count();
        $Page       = new \Think\Page($count,10);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('wechatuser')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    /*搜索用户*/
    public function ser()
    {
        $ser = i('post.ser');
        $where= array('like','%'.$ser.'%');
        if(IS_POST){
            if(trim(empty($ser))){
                $this->error('查询内容不能为空');
            }
            $count      = M('wechatuser')->where(['name'=>$where])->count();
            if($count==0){
                $this->error('没有找到你要找的内容,抱歉了。');
            }
            $Page       = new \Think\Page($count,10);
            $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
            $show       = $Page->show();
            $list = M('wechatuser')->where(['name'=>$where])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            $this->assign(['page'=>$show,'data'=>$list]);
            $this->display();
        }else{
            $this->display();
        }
    }
    /*禁用*/
    public function check()
    {
        $id = i('get.id');
        $user = M('wechatuser')->where(['id'=>$id])->find();
        if($user['check']==0){
            M('wechatuser')->where(['id'=>$id])->save(['check'=>1]);
            $this->redirect('User/index');
        }else{
            M('wechatuser')->where(['id'=>$id])->save(['check'=>0]);
            $this->redirect('User/index');
        }
    }
    /*会员*/
    public function vip()
    {
        $id = i('get.id');
        $user = M('wechatuser')->where(['id'=>$id])->find();
        if($user['isvip']==0){
            M('wechatuser')->where(['id'=>$id])->save(['isvip'=>1]);
            $this->redirect('User/index');
        }else{
            M('wechatuser')->where(['id'=>$id])->save(['isvip'=>0]);
            $this->redirect('User/index');
        }
    }
    /*经纪人*/
    public function jingjiren()
    {
        $id = i('get.id');
        $user = M('wechatuser')->where(['id'=>$id])->find();
        if($user['isjingjiren']==0){
            M('idcard')->where(['openid'=>$user['openid']])->save(['check'=>1]);
            M('wechatuser')->where(['id'=>$id])->save(['isjingjiren'=>1,'iszhuce'=>1]);
            $this->redirect('User/index');
        }else{
            M('idcard')->where(['openid'=>$user['openid']])->save(['check'=>0]);
            M('wechatuser')->where(['id'=>$id])->save(['isjingjiren'=>0,'iszhuce'=>0]);
            $this->redirect('User/index');
        }
    }
    //锁子搜索
    public function suoziser()
    {
        $ser = i('post.ser');
        $where= array('like','%'.$ser.'%');
        if(IS_POST){
            if(trim(empty($ser))){
                $this->error('查询内容不能为空');
            }
            $count      = M('webbuy')->where(['phone'=>$where])->count();
            if($count==0){
                $this->error('没有找到你要找的内容,抱歉了。');
            }
            $Page       = new \Think\Page($count,10);
            $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
            $show       = $Page->show();
            $list = M('webbuy')->where(['phone'=>$where])->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            $this->assign(['page'=>$show,'data'=>$list]);
            $this->display();
        }else{
            $this->display();
        }
    }
    //购买锁子
    public function suozi()
    {
        $count      = M('webbuy')->order('id desc')->count();
        $Page       = new \Think\Page($count,10);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('webbuy')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
}